import { useEffect, useState } from "react";
import { getArticleApi } from "../api/user";
import { useLoaderData, useLocation } from "react-router-dom";
function Xq() {
  let loaderData = useLoaderData();
  let [id, setId] = useState(loaderData.id);
  //   console.log(id);
  let [info, Infoset] = useState({});
  async function fn() {
    const res = await getArticleApi(id.id);
    console.log(res);
    Infoset(res);
  }
  useEffect(() => {
    fn();
  }, []);
  return (
    <div>
      <div>{info.content}</div>
      <div>{info.createdAt}</div>
      <div>{info.title}</div>
      <div>{info.updatedAt}</div>
    </div>
  );
}

export default Xq;

export const loader = ({ request }) => {
  let url = new URL(request.url);
  let obj = { ...Object.fromEntries(url.searchParams) };
  // console.log(obj);
  return { id: obj };
};
